package com.secret.chain.secretchain.config;//package com.secret.chain.secretchain.config;
//
//import com.secret.chain.secretchain.interceptor.JwtTokenUserInterceptor;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
//
//@Configuration
//public class WebMvcConfiguration extends WebMvcConfigurationSupport {
//    @Autowired
//    private JwtTokenUserInterceptor jwtTokenUserInterceptor;
//    protected void addInterceptors(InterceptorRegistry registry) {
//        System.out.println("拦截");
//        registry.addInterceptor(jwtTokenUserInterceptor)
//                .addPathPatterns("/wx/**")
//                .excludePathPatterns("/wx/user/login","/wx/user/regist");
//    }
//
//}


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/wx/**") // 匹配所有 /wx/ 开头的路径
                .allowedOrigins("http://localhost:8080") // 允许的前端地址
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 确保包含 OPTIONS
                .allowedHeaders("*")
                .allowCredentials(true);
    }
}